package com.cnap.multiclouldmgmt.model.enums;


import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * ------
 *告警级别枚举
 * @data 202211
 * @version 1.0
 * @describe
 * @author xc
 * ----
 **/
public enum AlarmLevelEnum {
    /**
     * 提示级别
     */
    PROMPT("提示", "prompt",1),
    /**
     * 次要级别
     */
    MINOR("次要", "minor",2),
    /**
     * 重要级别
     */
    MAJOR("重要", "major",3),
    /**
     * 紧急级别
     */
    EMERGENCY("紧急", "emergency",4);

    private final String message;
    private final String key;
    private final int order;


    AlarmLevelEnum(String message, String key,int order) {
        this.message = message;
        this.key = key;
        this.order = order;
    }

    /**
     * get
     *
     * @return Order
     */
    public int getOrder() {
        return order;
    }

    /**
     * get
     *
     * @return Message
     */
    public String getMessage() {
        return message;
    }

    /**
     * get
     *
     * @return Key
     */
    public String getKey() {
        return key;
    }

    //获取一堆告警里面最严重的那个
    public static String getMostOrderAlarmStr(List<String> alarms){

        String result = "";
        int maxOrder = 0;
        if ((alarms == null)||(alarms.isEmpty())){
            return result;
        }

        for (String alarm:alarms){
            AlarmLevelEnum alarmLevelEnum = getEnumByAlarm(alarm);
            if (alarmLevelEnum != null){
                if (alarmLevelEnum.getOrder() > maxOrder){
                    maxOrder = alarmLevelEnum.getOrder();
                    result = alarmLevelEnum.getMessage();
                }
            }
        }

        return result;
    }

    //获取一堆告警里面最严重的那个
    public static AlarmLevelEnum getEnumByAlarm(String alarm){

        for(AlarmLevelEnum enumObj : AlarmLevelEnum.values()){

            if (StringUtils.equals(enumObj.getMessage(),alarm)){

                return enumObj;
            }
        }

        return null;
    }
}
